Ext.ns('TaxonTagger');
TaxonTagger.comments = function(config){
	Ext.apply(this, config, {
			width: 400
		,	height: 300
		,	id: 'comments'
		,	modal: true
		,	resizable: false
		,	defaults: {
					padding: 5
				,	border: false
			}
		,	plain: true
		,	closable: true
		,	items: [{
					xtype: 'textarea'
				,	ref: 'txtComment'
				,	scope: this
				,	height: 230
				,	width: 383	
			}]
		,	buttonAlign: 'left'		
		,	buttons: [{
					text: this.txtClearComment
				,	scope: this	
				,	handler: function(){
						this.txtComment.setValue("");
						this.saveComment();
						this.close();
					}
			}, '->', {
					text: this.txtSaveClose
				,	scope: this
				,	handler: function(){
						if (this.txtComment.getValue() == "") {
							TaxonTagger.Notice.msg('Notice', 'Enter comment');
						}	else {
							this.saveComment();
							this.close();
						}
					}	
			}, {
					text: this.txtClose
				,	scope: this
				,	handler: function(){
						this.close();
					}	
			}]
	});
	
	TaxonTagger.comments.superclass.constructor.call(this, config);
	
};

Ext.extend(TaxonTagger.comments, Ext.Window, {

		saveComment: function() {
			var val = this.txtComment.getValue();
			if (Ext.isEmpty(val)) {
				delete TaxonTagger.currentDocument.comments[this.keyName];
				TaxonTagger.saveStorage();
			} else {
				TaxonTagger.currentDocument.comments[this.keyName] = val;
				TaxonTagger.saveStorage();
			}
		}

	,	loadComment: function() {
			this.txtComment.setValue(TaxonTagger.currentDocument.comments[this.keyName] || '');
		}

});